source('plotfdplnorm.R')
source('cenas/rndgen.R')

# citar estes valores "mean reps: 4.4914 sd reps: 3.91298571243476"

rfn <- function(m) rndgen(m, fdp, lfdp, M, lmean, lsd)
xs <- rep(0, 100)
ys <- rep(0, 100)

total <- 0
i <- 1
while(i <= 100) {
	xs[i] <- rlnorm(1, lmean,lsd)
	h <- M * lfdp(xs[i])
	ys[i] <- runif(1, 0,h)
	if(ys[i] <= fdp(xs[i]))
		i <- i+1
	total <- total+1
}

points(xs, ys,
	pch='x', cex=.75,
	col='black', lwd=2)

print(paste('para cada nro tive q fazer estas tentativas:', total/100))

PrintMinVar <- function(m) {
	m2 <- round(min_var(rfn, xlim[1], xlim[2], m, 0.05))
	print(paste('para erro 0.05 (m:', m, '):', m2))
	m2
}

m <- 1000
for(i in 1:4)
	m <- PrintMinVar(m)

